package com.example.xiaoyuan.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.xiaoyuan.pojo.Clazz;
import com.example.xiaoyuan.service.ClazzService;
import com.example.xiaoyuan.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "班级管理器")
@RestController
@RequestMapping("/sms/clazzController")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    @GetMapping("/getClazzs")
    public Result getClazzs(){

        List<Clazz> clazzes = clazzService.getClazzs();

        return Result.ok(clazzes);
    }


    /**
     * 根据id删除单个或多个班级
     * @param ids
     * @return
     */
    @DeleteMapping("/deleteClazz")
    public Result deleteClazz(@RequestBody List<Integer> ids){

        clazzService.removeByIds(ids);

        return Result.ok();
    }

    /**
     * 新增和修改年级
     * @param clazz
     * @return
     */
    @PostMapping("/saveOrUpdateClazz")
    public Result saveOrUpdateClazz(@RequestBody Clazz clazz){

        clazzService.saveOrUpdate(clazz);

        return Result.ok();
    }


    /**
     * 分页带条件查询班级信息
     * @param pageNo 页码
     * @param pageSize 每页条数
     * @param clazz 查询条件
     * @return
     */
    @GetMapping("/getClazzsByOpr/{pageNo}/{pageSize}")
    public Result getClazzByOpr(
            @PathVariable Integer pageNo,
            @PathVariable Integer pageSize,
            Clazz clazz){

        Page<Clazz> page = new Page<>(pageNo, pageSize);

        IPage<Clazz> iPage = clazzService.getClazzsByOpr(page,clazz);

        return Result.ok(iPage);
    }
}
